package com.ruoyi.project.charge.service.impl;

import com.ruoyi.project.charge.domin.ChargeDetail;
import com.ruoyi.project.charge.domin.ChargeQuery;
import com.ruoyi.project.charge.mapper.ChargeQueryMapper;
import com.ruoyi.project.charge.service.IChargeQueryService;
import com.ruoyi.project.charge.vo.ChargeParams;
import com.ruoyi.project.charge.vo.ChargeQueryParams;
import com.ruoyi.project.charge.vo.RefundParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @auther:YU JIANG
 * @date:2021/7/15
 * @time:10:53
 */
@Service
public class ChargeQueryServiceImpl implements IChargeQueryService {

    @Autowired
    private ChargeQueryMapper chargeQueryMapper;

    @Override
    public List<ChargeQuery> queryAll(ChargeQueryParams chargeQueryParams) {
        return chargeQueryMapper.selectAll(chargeQueryParams);
    }

    @Override
    public List<ChargeDetail> queryAll2(String order_id) {
        return chargeQueryMapper.selectAll2(order_id);
    }

    @Override
    @Transactional
    public int updateChargeQuery(RefundParams params) {
        int i=1;
        try {
            chargeQueryMapper.updateMCM(params);
            chargeQueryMapper.updateCharge(params);
            chargeQueryMapper.updateChargeDetail(params);
            //创建退款单
            chargeQueryMapper.insertRefund(params);
        } catch (Exception e) {
            e.printStackTrace();
            i=0;
        }
        return i;
    }


}
